package com.airbat.prize.modules.system.dal.mysql.area;

import cn.hutool.core.util.StrUtil;
import com.airbat.prize.common.pojo.PageResult;
import com.airbat.prize.modules.system.controller.area.vo.*;
import com.airbat.prize.modules.system.dal.dataobject.area.SysAreaDO;
import com.airbat.prize.mybits.mybatis.core.mapper.BaseMapperX;
import com.airbat.prize.mybits.mybatis.core.query.QueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 全国地区 Mapper
 *
 * @author 郑剑
 */
@Mapper
public interface SysAreaMapper extends BaseMapperX<SysAreaDO> {

    default PageResult<SysAreaDO> selectPage(SysAreaPageReqVO reqVO) {
        QueryWrapperX<SysAreaDO> queryWrapperX = new QueryWrapperX<>();
        queryWrapperX.likeIfPresent("NAME", reqVO.getName())
                .eqIfPresent("AREA_LEVEL", reqVO.getAreaLevel())
                .orderByAsc("CODE");
        if (StrUtil.isNotEmpty(reqVO.getParentCode())) {
            queryWrapperX.likeRight("PARENT_CODE", reqVO.getParentCode());
        }
        return selectPage(reqVO, queryWrapperX);
    }

    default List<SysAreaDO> selectList(SysAreaExportReqVO reqVO) {
        return selectList(new QueryWrapperX<SysAreaDO>()
                .likeIfPresent("NAME", reqVO.getName())
                .eqIfPresent("PARENT_CODE", reqVO.getParentCode())
                .eqIfPresent("AREA_LEVEL", reqVO.getAreaLevel())
                .eqIfPresent("LNG", reqVO.getLng())
                .eqIfPresent("LAT", reqVO.getLat())
                .orderByAsc("CODE"));
    }

}
